<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\GoodsComment;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;
use EasyWeChat\Message\Card;


class GoodsCommentController extends AdminController
{
    protected $title = '商品评论';
    /**
     * Make a grid builder.
     *
     * 何家令
     * 11.17
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new GoodsComment(), function (Grid $grid) {
            $grid->column('p_id',0,'')->table();
            $grid->column('goods_id');
            $grid->column('uid');
            $grid->column('comment');
            $grid->column('p_id');
            $grid->column('created_at');
            $grid->column('updated_at')->sortable();
            $grid->content->expand(function (Grid\Displayers\Expand $expand) {
                // 设置按钮名称
                $expand->button('回复');
                // 返回显示的详情
                //这里返回 content 字段内容，并用 Card 包裹起来

                return "<div style='padding:10px 10px 0'>6666</div>";
            });
            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');

            });
        });
    }
    public function selectData()
    {
        return $data=GoodsComment::get();
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     * 后台商品删除
     */
    protected function detail($id)
    {
        return Show::make($id, new GoodsComment(), function (Show $show) {
            $show->field('id');
            $show->field('goods_id');
            $show->field('uid');
            $show->field('comment');
            $show->field('p_id');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new GoodsComment(), function (Form $form) {
            $form->display('id');
            $form->text('goods_id');
            $form->text('uid');
            $form->text('comment');
            $form->text('p_id');

            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
